﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.PH5_2103A.Shopping.TEntityFrame.IService
{
    /// <summary>
    /// CRUD的基本操作的服务接口
    /// </summary>
    public interface IBaseService<T> where T : class
    {

        #region Insert -- 添加
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns>返回受影响行数</returns>
        int Insert(T t);

        /// <summary>
        /// 批量添加数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns>返回受影响行数</returns>
        int Insert(List<T> list);

        #endregion

        #region Update -- 修改
        /// <summary>
        /// 修改一条数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns>返回受影响行数</returns>
        int Update(T t);

        /// <summary>
        /// 批量修改数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns>返回受影响行数</returns>
        int Update(List<T> list);
        #endregion

        #region Delete -- 删除
        /// <summary>
        /// 根据实体删除一条数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns>返回受影响行数</returns>
        int Delete(T t);

        /// <summary>
        /// 根据实体批量删除数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns>返回受影响行数</returns>
        int Delete(List<T> list);

        /// <summary>
        /// 根据ID删除一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns>返回受影响行数</returns>
        int Delete(object id);

        /// <summary>
        /// 根据ID批量删除数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns>返回受影响行数</returns>
        int Delete(List<object> ids);
        #endregion

        #region Select -- 查询
        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <returns></returns>
        IQueryable<T> Select();

        /// <summary>
        /// 根据ID查询一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T SelectFirstById(object id);

        /// <summary>
        /// 查询分页数据
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="total">总条数</param>
        /// <returns></returns>
        IQueryable<T> Select(int pageIndex, int pageSize,out int total);

        /// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="where">查询条件的表达式</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="total">总条数</param>
        /// <returns></returns>
        IQueryable<T> Select(System.Linq.Expressions.Expression<Func<T,bool>> where,int pageIndex,int pageSize,out int total);

        /// <summary>
        /// 根据条件分页查询并排序
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="where">查询表达式</param>
        /// <param name="sort">排序表达式</param>
        /// <param name="isAsc">是升序还是降序</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="total">总条数</param>
        /// <returns></returns>
        IQueryable<T> Select<TKey>(System.Linq.Expressions.Expression<Func<T, bool>> where,Func<T,TKey> sort,bool isAsc, int pageIndex, int pageSize, out int total);
        #endregion
    }
}
